{extend name="$base" /}
{block name="resources"}
<style>
.data-loading-eject-layer{
	width: 100%;
	height: 100%;
	position: fixed;
	top: 0;
	left: 0;
	z-index: 10000;
	background:rgba(0,0,0,0.4);
	display: none;
}	
.prompt_information{
	width: 200px;
	height: 200px;
	position: relative;
	margin:auto;
	background: #fff;
	top: 30%;
    box-shadow: 0 0 6px -1px #bbb;
    border-radius: 20px;
}
.prompt_information .load-icon{
	width: 150px;
	height: 150px;
	line-height: 200px;
	margin:0 auto;
	text-align: center;
}
.prompt_information .load-icon i{
	color: #bbb;
}
.prompt_information .information{
	height: 50px;
	text-align: center;
}
.progress_bar{
	width: 90%;
	margin: 5px auto;
	height: 5px;
	border:1px solid #ddd;
}
.progress_bar .speed_of_progress{
	width: 3%;
	height: 5px;
	background: #0689e1;
}
.btn-common-delete:hover{
	color: #fff;
}
.btn-common-delete {
    background: #0059d6;
}
.mytable th {
    padding-left: 0px;
}
</style>
{/block}
{block name="main"}
<table class="mytable">
	<tr>
		<th width="5%">
			<button class="btn-common" id="UpdateFansList" href="javascript:;" style="float: left;">
				<i class="fa fa-refresh" aria-hidden="true"></i>
				<span>更新粉丝列表</span>
			</button>
		</th>
		<th width="10%">
			<input type="text" id='search_text' placeholder="请输入粉丝名称" class="input-common"/>
			<button onclick="searchData()" value="搜索" class="btn-common">搜索</button>
		</th>
	</tr>
</table>
<table class="table-class">
	<colgroup>
		<col style="width: 2%;">
		<col style="width: 16%;">
		<col style="width: 18%;">
		<col style="width: 16%;">
		<col style="width: 16%;">
		<col style="width: 16%;">
		<col style="width: 16%;">
	</colgroup>
	<thead>
		<tr align="center">
			<th><i class="checkbox-common"><input type="checkbox" ></i></th>
			<th align="left">粉丝头像</th>
			<th align="left">粉丝名称</th>
			<th align="left">地址</th>
			<th>关注状态</th>
			<th>关注时间</th>
			<th align="left">备注</th>
		</tr>
	</thead>
	<tbody></tbody>
</table>
<!-- 更新遮罩层 -->
<div class="data-loading-eject-layer">
	<div class="prompt_information">
		<div class="load-icon"><i class="fa fa-refresh fa-spin fa-5x fa-fw"></i></div>
		<div class="progress_bar">
			<div class="speed_of_progress"></div>
		</div>
		<p class="information">正在更新中</p>
	</div>
</div>

{/block}
{block name="script"}
<script type="text/javascript">
function LoadingInfo(page_index) {
	var search_text = $("#search_text").val();
	$.ajax({
		type : "post",
		url : "{:__URL('ADMIN_MAIN/member/weixinfanslist')}",
		data : {
			"page_index" : page_index, "page_size" : $("#showNumber").val(), "search_text" : search_text
		},
		success : function(data) {
			if (data["data"].length > 0) {
				$(".table-class tbody").empty();
				for (var i = 0; i < data["data"].length; i++) {
					var html = '';
					var is_subscribe = "";
					var sex = "";
					if(data["data"][i]["is_subscribe"] == 1){
						is_subscribe = "已关注";
					}else{
						is_subscribe = "取消关注";
					}
					if(data["data"][i]["sex"] == 1){
						sex = '男';
					}else{
						sex = '女';
					}
					var country = "";
					var province = "";
					var city = "";
					var district = "";
					if(data["data"][i]["country"] != "无"){
						country = data["data"][i]["country"];
					}
					if(data["data"][i]["province"] != "无"){
						province = data["data"][i]["province"];
					}
					if(data["data"][i]["city"] != "无"){
						city = data["data"][i]["city"];
					}
					if(data["data"][i]["district"] != "无"){
						district = data["data"][i]["district"];
					}
					
					html += '<tr align="center">';
					html += '<td><i class="checkbox-common"><input name="sub" type="checkbox" value="'+ data["data"][i]["fans_id"]+'" ></i></td>';
					html += '<td align="left">';
					if(data["data"][i]["headimgurl"] ==""){
						html += '<img src="__STATIC__/images/default_user_portrait.gif" class="head-portrait" />';
					}else{
						html += '<img src="'+data["data"][i]["headimgurl"]+'" class="head-portrait" />';
					}
					html += '</td>';
					if (data["data"][i]["nickname_decode"] == null || "" == data["data"][i]["nickname_decode"]) {
						html += '<td align="left">--</td>';
					} else {
						html += '<td align="left">' + data["data"][i]["nickname_decode"] + '</td>';
					}
					html += '<td align="left">' + country +province +city+district +'</td>';
					
					html += '<td>' + is_subscribe + '</td>';
					html += '<td>' + timeStampTurnTime(data["data"][i]["subscribe_date"]) + '</td>';
					html += '<td align="left">' + data["data"][i]["memo"] + '</td>';
					html += '</tr>';
					$(".table-class tbody").append(html);
				}
			} else {
				var html = '<tr align="center"><td colspan="9">暂无符合条件的数据记录</td></tr>';
				$(".table-class tbody").html(html);
			}
			initPageData(data["page_count"],data['data'].length,data['total_count']);
			$("#pageNumber").html(pagenumShow(jumpNumber,$("#page_count").val(),{$pageshow}));
		}
	});
}

function searchData(){
	LoadingInfo(1);
}

var page_count = 0;
var pageIndex = 0;
$("#UpdateFansList").click(function(){
	$.ajax({
		type : "post",
		url : "{:__URL('ADMIN_MAIN/member/updateWchatFansList')}",
		data : { "page_index" : pageIndex},
		beforeSend:function(){
			$(".data-loading-eject-layer").fadeIn();
		},
		success : function(data){
			if(pageIndex == 0){
				page_count = data["page_count"];
			}
			if(data["errcode"] != undefined && data["errcode"] < 0){
				$(".data-loading-eject-layer").fadeOut();
				showTip(data['errorMsg'],'error');
			}else if(data["errcode"] == 0){
				if(pageIndex <= page_count){
					pageIndex = parseInt(pageIndex) + 1;
					$("#UpdateFansList").click();
					if(pageIndex <= page_count){
						var speed_of_progress =  pageIndex/page_count * 100;
						$(".speed_of_progress").width(speed_of_progress+'%');
						$(".information").text('当前已完成'+pageIndex+'/'+page_count);
					}
				}else{
					$(".data-loading-eject-layer").fadeOut();
					showTip(data['message'],'success');
					location.href = "{:__URL('ADMIN_MAIN/member/weixinfanslist')}";
				}
			}
		}
	});
})
</script>
{/block}